package com.yykj.hospital.server.controller;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.yykj.common.enums.HospitalNavigatorType;
import com.yykj.common.vo.PageData;
import com.yykj.common.vo.ResultVO;
import com.yykj.hospital.server.form.*;
import com.yykj.hospital.server.model.entity.HospitalGuide;
import com.yykj.hospital.server.model.entity.HospitalNavigator;
import com.yykj.hospital.server.model.entity.HospitalNotice;
import com.yykj.hospital.server.model.entity.HospitalTraffic;
import com.yykj.hospital.server.service.HospitalGuideService;
import com.yykj.hospital.server.service.HospitalNavigatorService;
import com.yykj.hospital.server.service.HospitalNoticeService;
import com.yykj.hospital.server.service.HospitalTrafficService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/backstage/hospital")
@Api(tags = {"医院介绍配置"})
@SuppressWarnings("unchecked")
public class HospitalIntroduceController {

    @ApiOperation("医院指南--创建")
    @PostMapping("/guide/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalGuide> addHospitalGuide(@RequestBody HospitalGuideEditForm form) {
        return ResultVO.success(guideService.editHospitalGuide(form));
    }

    @ApiOperation("医院指南--修改")
    @PutMapping("/guide/edit")
    public ResultVO<HospitalGuide> editHospitalGuide(@RequestBody HospitalGuideEditForm form) {
        return ResultVO.success(guideService.editHospitalGuide(form));
    }

    @ApiOperation("医院指南--删除")
    @DeleteMapping("/guide/delete/{id}")
    public ResultVO<HospitalGuide> deleteHospitalGuide(@PathVariable Integer id) {
        guideService.deleteHospitalGuide(id);
        return ResultVO.success();
    }

    @ApiOperation("医院指南--列表")
    @GetMapping("/guide/list")
    public ResultVO<PageData<HospitalGuide>> editHospitalGuide(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                     @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                     @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                     @RequestParam(name = "status", required = false) Boolean status,
                                                     @RequestParam(name = "keyword", required = false) String keyword) {

        HospitalGuideListForm form = HospitalGuideListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .status(status)
                .keyword(keyword)
                .build();

        return ResultVO.success(guideService.listHospitalGuide(form));
    }

    //=============================================================================================================
    @ApiOperation("医院公告--创建")
    @PostMapping("/notice/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalNotice> addHospitalNotice(@RequestBody HospitalNoticeEditForm form) {
        return ResultVO.success(noticeService.editHospitalNotice(form));
    }

    @ApiOperation("医院公告--修改")
    @PutMapping("/notice/edit")
    public ResultVO<HospitalNotice> editHospitalNotice(@RequestBody HospitalNoticeEditForm form) {
        return ResultVO.success(noticeService.editHospitalNotice(form));
    }

    @ApiOperation("医院公告--删除")
    @DeleteMapping("/notice/delete/{id}")
    public ResultVO<HospitalNotice> deleteHospitalNotice(@PathVariable Integer id) {
        noticeService.deleteHospitalNotice(id);
        return ResultVO.success();
    }

    @ApiOperation("医院公告--列表")
    @GetMapping("/notice/list")
    public ResultVO<PageData<HospitalNotice>> editHospitalNotice(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                       @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                       @RequestParam(name = "status", required = false) Boolean status,
                                                       @RequestParam(name = "keyword", required = false) String keyword) {

        HospitalNoticeListForm form = HospitalNoticeListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .keyword(keyword)
                .status(status)
                .build();

        return ResultVO.success(noticeService.listHospitalNotice(form));
    }

    //=============================================================================================================
    @ApiOperation("院内导行--创建")
    @PostMapping("/navigator/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalNavigator> addHospitalNavigator(@RequestBody HospitalNavigatorEditForm form) {
        return ResultVO.success(navigatorService.editHospitalNavigator(form));
    }

    @ApiOperation("院内导行--修改")
    @PutMapping("/navigator/edit")
    public ResultVO<HospitalNavigator> editHospitalNavigator(@RequestBody HospitalNavigatorEditForm form) {
        return ResultVO.success(navigatorService.editHospitalNavigator(form));
    }

    @ApiOperation("院内导行--删除")
    @DeleteMapping("/navigator/delete/{id}")
    public ResultVO<HospitalNavigator> deleteHospitalNavigator(@PathVariable Integer id) {
        navigatorService.deleteHospitalNavigator(id);
        return ResultVO.success();
    }

    @ApiOperation("院内导行--列表")
    @GetMapping("/navigator/list")
    public ResultVO<PageData<HospitalNavigator>> editHospitalNavigator(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                                       @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                                       @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                                       @RequestParam(name = "status",required = false) Boolean status,
                                                                       @RequestParam(name = "type",required = false) HospitalNavigatorType type,
                                                                       @RequestParam(name = "keyword", required = false) String keyword) {

        HospitalNavigatorListForm form = HospitalNavigatorListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .type(type)
                .pageSize(pageSize)
                .keyword(keyword)
                .status(status)
                .build();

        return ResultVO.success(navigatorService.listHospitalNavigator(form));
    }

    //=============================================================================================================
    @ApiOperation("医院交通--创建")
    @PostMapping("/traffic/add")
    @ApiOperationSupport(ignoreParameters = {"id"})
    public ResultVO<HospitalTraffic> addHospitalTraffic(@RequestBody HospitalTrafficEditForm form) {
        return ResultVO.success(trafficService.editHospitalTraffic(form));
    }

    @ApiOperation("医院交通--修改")
    @PutMapping("/traffic/edit")
    public ResultVO<HospitalTraffic> editHospitalTraffic(@RequestBody HospitalTrafficEditForm form) {
        return ResultVO.success(trafficService.editHospitalTraffic(form));
    }

    @ApiOperation("医院交通--删除")
    @DeleteMapping("/traffic/delete/{id}")
    public ResultVO<HospitalTraffic> deleteHospitalTraffic(@PathVariable Integer id) {
        trafficService.deleteHospitalTraffic(id);
        return ResultVO.success();
    }

    @ApiOperation("医院交通--列表")
    @GetMapping("/traffic/list")
    public ResultVO<PageData<HospitalTraffic>> editHospitalTraffic(@RequestParam(name = "hospitalId") Integer hospitalId,
                                                             @RequestParam(name = "currentPage", defaultValue = "1") Integer currentPage,
                                                             @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                                             @RequestParam(name = "status",required = false) Boolean status,
                                                             @RequestParam(name = "keyword", required = false) String keyword) {

        HospitalTrafficListForm form = HospitalTrafficListForm.builder()
                .hospitalId(hospitalId)
                .currentPage(currentPage)
                .pageSize(pageSize)
                .keyword(keyword)
                .status(status)
                .build();

        return ResultVO.success(trafficService.listHospitalTraffic(form));
    }

    //=============================================================================================================


    private HospitalGuideService guideService;

    private HospitalNoticeService noticeService;

    private HospitalNavigatorService navigatorService;

    private HospitalTrafficService trafficService;

    @Autowired
    public void setGuideService(HospitalGuideService guideService) {
        this.guideService = guideService;
    }

    @Autowired
    public void setNoticeService(HospitalNoticeService noticeService) {
        this.noticeService = noticeService;
    }

    @Autowired
    public void setNavigatorService(HospitalNavigatorService navigatorService) {
        this.navigatorService = navigatorService;
    }
    @Autowired
    public void setTrafficService(HospitalTrafficService trafficService) {
        this.trafficService = trafficService;
    }
}
